package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: sky-take-out
 * @description:
 * @author: 酷炫焦少
 * @create: 2024-11-18 10:52
 **/
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端-购物车接口")
public class ShoppingCartController {

    @Resource
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result<String> add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        return shoppingCartService.add(shoppingCartDTO);
    }

    @GetMapping("/list")
    @ApiOperation("购物车列表")
    public Result<List<ShoppingCart>> list() {
        return shoppingCartService.list();
    }

    @PostMapping("/sub")
    @ApiOperation("减少某个商品的数量")
    public Result<String> sub(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        return shoppingCartService.sub(shoppingCartDTO);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result<String> clean() {
        return shoppingCartService.clean();
    }

}
